grApp.filter('isSign',function(){
    var result='';
    return function(item,signDay){
        if(item===0){
            result='未签到';
        }else{
            result='签到'+signDay+'天';
        }
        return result;
    };
});
var flag = 0;
//首页操作的控制器
grApp.controller('HomeCtrl',['$scope','BaseService','toaster',function($scope,BaseService,toaster){
    $scope.sign = function(){
        //alert('>_< ! 抱歉哦,亲 ! \n该功能升级中,程序猿正在疯狂的写代码... 等等有惊喜!~');
        if($scope.isSignToday == 1){
            window.location.href="/activity/signday";
        }else{
            BaseService.setSignDayAction().then(function (result) {
                if(result.code === 0){
                    $scope.isSignToday = 1;
                    $scope.allSignDay = result.updateUser.AllSignDay ;
                    flag = 1;
                }else{
                    $scope.isSignToday = 0;
                }
            }).catch(function(err){
                $scope.isSignToday = 0;
                logger.error(err);
            });
        }
    };
    $scope.addToCart = function(pid,sid,num){
        BaseService.addToCart(pid,sid,num).then(function(res){
            //console.log(res.reason.code);
            if(res.code==259){
                if(res.reason.code==-1){
                    toaster.error('库存不足');
                }
            }else{
                toaster.success('添加成功');
            }
        }).catch(function(err){
            toaster.error('添加失败');
        });
    }
    $scope.load = function(isSign,allSignDay){
        //初始化时获取isSignToday的状态
        // result.SignState ===0  未签到 ===1是已签到
        $scope.isSignToday = isSign ;
        $scope.allSignDay = allSignDay ;

    }

    //签到按钮点击事件
    $scope.signBtn = function () {

    };

}]);
